package cn.fsw.pethome.base.controller;

import cn.fsw.pethome.base.domain.dto.VerifyDTO;
import cn.fsw.pethome.base.service.IVerifyCodeService;
import cn.fsw.pethome.util.AjaxResult;
import cn.fsw.pethome.util.BusinessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {
    @Autowired
    private IVerifyCodeService iVerifyCodeService;

    /*图片验证码*/
    @GetMapping("/image/{key}")
    public AjaxResult VerifyCode(@PathVariable("key") String key){
        try {
            String code = iVerifyCodeService.VerifyCode(key);
            return AjaxResult.ajaxResult().setData(code);
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.error().setMsg(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error();
        }
    }
    /*获取手机验证码*/
    @PostMapping("/sendMobileCode")
    public AjaxResult sendMobileCode(@RequestBody VerifyDTO verifyDTO){
        try {
            iVerifyCodeService.sendMobileCode(verifyDTO);
            return AjaxResult.ajaxResult();
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.error().setMsg(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error();
        }
    }
}
